package io.gitee.hchaojie.day08;

import org.junit.Test;

import java.io.*;

public class TestFile {
    @Test
    public void testFile() throws IOException {
        File file = new File("D:\\test.txt");

        // 受检异常，必须显式的try...catch
        try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file))) {
            reader.read();
        } catch (FileNotFoundException e) {
            // 往文件里面写
            e.printStackTrace();        // 往控制台打异常消息，是一个不规范的处理

        } catch (IOException e) {
            throw e;
        } finally {
            System.out.println("");
        }
    }

    @Test
    public void testRuntimeException() {

        try {
            // File f = null;
            // f.exists();

            // return;
            System.exit(0);
        } catch (Throwable e) {
            System.out.println("空指针异常");
            e.printStackTrace();
        } finally {
            System.out.println("finally...");
        }
    }
}
